<< define "user/create.html" >>
<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>添加用户</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8"/>
    <link rel="stylesheet" href="/static/css/font.css">
    <link rel="stylesheet" href="/static/css/xadmin.css">
    <link rel="stylesheet" href="/static/css/mbgadmin.css">
    <script src="/static/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/static/js/xadmin.js"></script>
    <script type="text/javascript" src="/static/js/mbgadmin.js"></script>
</head>
<body>
<form class="layui-form">
    <div class="layui-form-item">
        <label class="layui-form-label">用户名<span class="x-red">*</span></label>
        <div class="layui-input-block">
            <input type="text" name="name" lay-verify="required" placeholder="请输入用户名" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">密码<span class="x-red">*</span></label>
        <div class="layui-input-block">
            <input type="password" name="password" lay-verify="required" placeholder="请输入登陆密码" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">确认密码<span class="x-red">*</span></label>
        <div class="layui-input-block">
            <input type="password" name="verify_password" lay-verify="required" placeholder="请输入登陆密码" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">手机</label>
        <div class="layui-input-block">
            <input type="text" name="phone" placeholder="请输入手机号" autocomplete="off" class="layui-input"
                   lay-verify="phone">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">邮箱</label>
        <div class="layui-input-block">
            <input type="text" name="email" placeholder="请输入邮箱" autocomplete="off" class="layui-input"
                   lay-verify="email">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">性别<span class="x-red">*</span></label>
        <div class="layui-input-block">
            <input type="radio" name="sex" value="1" title="男" checked>
            <input type="radio" name="sex" value="0" title="女">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">状态<span class="x-red">*</span></label>
        <div class="layui-input-block">
            <input type="radio" name="status" value="1" title="启用" checked>
            <input type="radio" name="status" value="0" title="禁用">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">角色</label>
        <div class="layui-input-block" id="role"></div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="addAdmin" id="submit">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>

<script>
    layui.use(['form','transfer','jquery'], function () {
        var form = layui.form;
        let $ = layui.jquery;
        let transfer = layui.transfer;
        $.get("/users/getRole",function (data){
            transfer.render({
                elem: '#role',
                id:'role',
                showSearch:true,
                title:['角色列表','已选中角色列表'],
                data: data
            });
        })

        form.on('submit(addAdmin)', function (data) {
            $("#submit").addClass("layui-btn-disabled") //防止连续点击添加键。
            let loadIndex = layer.load(2);
            var getData = transfer.getData('role');
            const rolesValues = getData.map(role => role.value).join(',');
            data.field.roles = rolesValues
            $.post("/users/create", data.field, function (result) {
                if (result.code === 0) {
                    layer.close(loadIndex)
                    parent.layer.msg(result.msg);
                    ReloadLists()
                } else {
                    $("#submit").removeClass("layui-btn-disabled")
                    layer.close(loadIndex)
                    parent.layer.msg(result.msg);
                }
            });
            return false;
        });
    });
</script>

</body>
</html>
<< end >>